﻿using System;

namespace YJKGridTopologyCal.Algorithm
{
	public static class BoundaryNodeRules
	{
		public static readonly IBoundaryNodeRule Mod2BoundaryRule = new BoundaryNodeRules.Mod2BoundaryNodeRule();

		public static readonly IBoundaryNodeRule EndpointBoundaryRule = new BoundaryNodeRules.EndPointBoundaryNodeRule();

		public static readonly IBoundaryNodeRule MultivalentEndpointBoundaryRule = new BoundaryNodeRules.MultiValentEndPointBoundaryNodeRule();

		public static readonly IBoundaryNodeRule MonoValentEndpointBoundaryRule = new BoundaryNodeRules.MonoValentEndPointBoundaryNodeRule();

		public static readonly IBoundaryNodeRule OgcSfsBoundaryRule = BoundaryNodeRules.Mod2BoundaryRule;

		private class Mod2BoundaryNodeRule : IBoundaryNodeRule
		{
			public bool IsInBoundary(int boundaryCount)
			{
				return boundaryCount % 2 == 1;
			}
		}

		private class EndPointBoundaryNodeRule : IBoundaryNodeRule
		{
			public bool IsInBoundary(int boundaryCount)
			{
				return boundaryCount > 0;
			}
		}

		private class MultiValentEndPointBoundaryNodeRule : IBoundaryNodeRule
		{
			public bool IsInBoundary(int boundaryCount)
			{
				return boundaryCount > 1;
			}
		}

		private class MonoValentEndPointBoundaryNodeRule : IBoundaryNodeRule
		{
			public bool IsInBoundary(int boundaryCount)
			{
				return boundaryCount == 1;
			}
		}
	}
}
